/*Figure 1*/
/*load yearbook_INGOs.dta*/
line number year, xlabel(1950(20)2010) scale(1.2)

/*Figure 2*/
/*load yearbook_US_foundings.dta"*/
line foundings year, xlabel(1950(20)2010) scale(1.2)

/*Figure 3*/
/*load NCCS data on nonprofit tax filings*/
/*data cannot be shared by researchers due to license restrictions*/
/*please contact authors for information about how to purchase access*/
sort ein
quietly by ein: gen dup = cond(_N==1, 0, _n)
drop if dup>1
drop dup /*remove duplicates*/
generate field=.
replace field=1 if nteefina=="Q33"
replace field=2 if nteefina=="Q35"
replace field=3 if nteefina=="Q38"
replace field=4 if nteefina=="Q39"
label define fieldgroups 1 "Relief" 2 "Democracy" 3 "Environment" 4 "Health" 
label values field fieldgroups
drop if field==. /*remove other fields*/
destring ruledate, replace
drop if ruledate==. | ruledate<190000 /*remove NGOs with no IRS rule dates*/
generate foundingyear=int(ruledate/100)
destring fisyr, replace
keep if foundingyear>1991 & foundingyear<2013 /*remove irrelevant years*/
generate founded=1
by field foundingyear, sort: generate foundings=sum(founded)
collapse (max) foundings, by(field foundingyear)
label variable foundings "number"
label variable foundingyear "year"
sort field foundingyear
line foundings foundingyear if field==1, title({bf: Relief}) name(relief) nodraw scale(1.2)
line foundings foundingyear if field==2, title({bf: Democracy}) name(democracy) nodraw scale(1.2)
line foundings foundingyear if field==3, title({bf: Conservation}) name(environment) nodraw scale(1.2)
line foundings foundingyear if field==4, title({bf: Health}) name(health) nodraw scale(1.2)
graph combine environment democracy health relief
graph drop environment democracy health relief

/*Figure 4*/
/*load NCCS data on nonprofit tax filings*/
/*data cannot be shared by researchers due to license restrictions*/
/*please contact authors for information about how to purchase access*/
generate field=.
replace field=1 if nteefina=="Q33"
replace field=2 if nteefina=="Q35"
replace field=3 if nteefina=="Q38"
replace field=4 if nteefina=="Q39"
label define fieldgroups 1 "Relief" 2 "Democracy" 3 "Environment" 4 "Health" 
label values field fieldgroups
drop if field==. /*remove other fields*/
by field fisyr, sort: egen resources=sum(totrev)
keep field fisyr resources
quietly by field fisyr: gen dup = cond(_N==1, 0, _n)
drop if dup>1
drop dup
rename fisyr year
destring year, replace
keep if year>1991 & year<2012 /*remove irrelevant years*/
replace resources=resources/1000000
label variable resources "millions of dollars"
sort field year
line resources year if field==1, xlabel(1990(5)2010) title({bf: Relief}) name(relief) nodraw scale(1.2)
line resources year if field==2, xlabel(1990(5)2010) title({bf: Democracy}) name(democracy) nodraw scale(1.2)
line resources year if field==3, xlabel(1990(5)2010) title({bf: Conservation}) name(environment) nodraw scale(1.2)
line resources year if field==4, xlabel(1990(5)2010) title({bf: Health}) name(health) nodraw scale(1.2)
graph combine environment democracy health relief
graph drop environment democracy health relief

/*Table 1*/
/*load main_analysis_data*/
/*excluded variables are foundings, density, density squared, population age*/
/*data cannot be shared by researchers due to NCCS license restrictions*/
/*please contact authors for information about how to purchase access*/
reg foundings log_commitment density, vce(cluster field)
reg foundings log_commitment density density_sq, vce(cluster field)
reg foundings log_commitment density density_sq lnmedia lncongress igos, vce(cluster field)
reg foundings log_commitment density density_sq lnmedia lncongress igos popage i.field, vce(cluster field)
